package com.rp.system.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.rp.common.aspect.annotetion.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 用户表
 * </p>
 *
 * @author vicente
 * @since 2020-11-23
 */
//@RequestBody传递对象时 忽略不认识的属性
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "SysUser对象", description = "用户表")
public class SysUser extends Model<SysUser> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.UUID)
    @ApiModelProperty(value = "主键id")
    private String id;

    @ApiModelProperty(value = "登录账号")
    private String username;

    @ApiModelProperty(value = "真实姓名")
    private String realname;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "md5密码盐")
    @TableId(value = "salt", type = IdType.UUID)
    private String salt;

    @ApiModelProperty(value = "头像")
    private String avatar;

    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    @ApiModelProperty(value = "生日")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate birthday;

    @Dict(dicCode = "sex")
    @ApiModelProperty(value = "性别(0-默认未知,1-男,2-女)")
    private Integer sex;

    @ApiModelProperty(value = "电子邮件")
    @Email
    private String email;

    @ApiModelProperty(value = "电话")
    private String phone;

    @ApiModelProperty(value = "状态(1-正常,2-冻结)", example = "1")
    private Integer status;

    @ApiModelProperty(value = "删除状态(0-正常,1-已删除)", hidden = true)
    @TableLogic
    private Integer delFlag;

    @ApiModelProperty(value = "第三方登录的唯一标识")
    private String thirdId;

    @ApiModelProperty(value = "第三方类型")
    private String thirdType;

    @ApiModelProperty(value = "同步工作流引擎(1-同步,0-不同步)", example = "1")
    private Integer activitiSync;


    @ApiModelProperty(value = "职务，关联职务表")
    private String post;

    @ApiModelProperty(value = "验证码")
    @TableField(exist = false)
    private String code;
    @ApiModelProperty(value = "座机号")
    private String telephone;

    @ApiModelProperty(value = "创建人")
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty(value = "更新人")
    @TableField(fill = FieldFill.UPDATE)
    private String updateBy;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "身份（1普通成员 2上级）", example = "1")
    private Integer userIdentity;


    @ApiModelProperty(value = "设备ID")
    private String clientId;


    @ApiModelProperty(value = "角色集合")
    @TableField(exist = false)
    private List<String> roleIdList;


    @ApiModelProperty(value = "角色集合")
    @TableField(exist = false)
    private List<SysUserRole> roleList;

    @ApiModelProperty(value = "部门Id集合")
    @TableField(exist = false)
    private List<String> departIdList;

    @ApiModelProperty(value = "权限perms集合")
    @TableField(exist = false)
    private List<String> PermissionPermsList;

    @ApiModelProperty(value = "角色")
    @TableField(exist = false)
    private String roleName;

    @ApiModelProperty(value = "TOKEN")
    @TableField(exist = false)
    private String token;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
